[None][feat] Update the deepseek routing#13186
[None][feat] Update the deepseek routing#13186ChristinaZ wants to merge 2 commits intoNVIDIA:mainfrom
Conversation
Summary: Supported-Configuration Changes Before vs. After PR #13186This PR broadens the range of MoE routing configurations that can use the fused 1.
|
| Dimension | Before | After | Net change |
|---|---|---|---|
num_experts |
≤ 512 (Python gate), but combined with the (topk_group == 1 && top_k != 22) fallback clause, only (num_experts, top_k) = (512, 22) actually reached the fused path |
≤ 1024 | Virtually the entire num_experts ∈ [1, 1024] space is newly opened |
top_k |
Effectively only == 22 (Nemotron Super v3 special case). All other top_k values — including top_k ≤ 8 — fell back to PyTorch because topk_group == 1 combined with top_k != 22 forced fallback |
≤ 32 | Newly opened: {1..21, 23..32}, i.e. {1..32} \ {22} |
topk_group |
Non-trivial combined constraint that excluded all topk_group == 1 configs except top_k == 22 |
No effective constraint (since n_group == 1 implies topk_group == 1 anyway) |
— |
In practice, the n_group == 1 fused path went from a single supported point (Nemotron Super v3, (512, 1, 1, 22)) to essentially the full practical space (any num_experts ≤ 1024, any top_k ≤ 32). Models like Kimi K2 ((384, 1, 1, 8)) and any ≤ 1024-expert single-group model now benefit from the fused kernel.
2. n_group > 1 branch (grouped routing)
| Dimension | Before | After | Net change |
|---|---|---|---|
num_experts |
≤ 256 | ≤ 256 | unchanged |
experts_per_group |
≤ 32 (= WARP_SIZE) | ≤ 32 | unchanged |
top_k |
≤ 8 (implicit via MaxNumTopExperts default) |
≤ 8 (now explicit in the host dispatch) | unchanged |
experts_per_group × topk_group |
≤ 128 | ≤ 256 | Doubled; new zone is (128, 256] |
Within the num_experts ≤ 256, experts_per_group ≤ 32 envelope, the only axis that was expanded is experts_per_group × topk_group, and the expansion happens by doubling the ceiling from 128 to 256. This is implemented by templating MaxNumTopGroups (previously hardcoded to 4) and instantiating a second kernel variant with MaxNumTopGroups = 8 for the new upper band.
DeepSeek-V3's production config (256, 8, 4, 8) is at the old ceiling (32 × 4 = 128) and still takes the default (MaxNumTopGroups = 4) path. New configurations such as (224, 8, 7, 8) (product 196) or (256, 8, 8, 8) (product 256) now dispatch to the MaxNumTopGroups = 8 instance.
b100f3b to
24dec37
Compare
|
/bot run --disable-fail-fast |
📝 WalkthroughWalkthroughRefactors top-k sorting logic by implementing a complete sorting network, updates MoE kernel constants and dispatch predicates, adds validation guards for intranode expert constraints, updates routing compatibility gating, and extends test parameterization for deepseek configurations. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unittest/_torch/thop/parallel/test_noaux_tc.py (1)
8-19: Good coverage expansion, but consider adding a case for the newMaxNumTopGroups=8kernel path.The new parameterization covers:
- Single-group: (72,1,1,6), (384,1,1,8), (512,1,1,22), (1024,1,1,32), (512,1,1,32) — all within the updated limits
- Multi-group: (256,8,4,8), (256,8,2,8) — uses
DefaultMaxNumTopGroups=4path- Fallback: (512,8,6,8) — correctly falls back since
experts_per_group=64 > 32However, there's no test case that exercises the new
LargeMaxNumTopGroups=8kernel path introduced innoAuxTcKernels.cu. This path is triggered whenexperts_per_group * topk_group > 128but≤ 256.Consider adding a case like
(256, 8, 6, 8)which hasexperts_per_group=32andtopk_group=6, giving a product of192that would dispatch to theMaxNumTopGroups=8variant.💡 Suggested addition
`@pytest.mark.parametrize`( "num_experts, n_group, topk_group, top_k", [ (256, 8, 4, 8), (72, 1, 1, 6), (384, 1, 1, 8), (512, 1, 1, 22), (1024, 1, 1, 32), (512, 1, 1, 32), (256, 8, 2, 8), + (256, 8, 6, 8), # LargeMaxNumTopGroups path (32*6=192 > 128) (512, 8, 6, 8), # fallback ])🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unittest/_torch/thop/parallel/test_noaux_tc.py` around lines 8 - 19, Add a new parameterized test case to exercise the MaxNumTopGroups=8 kernel path by inserting the tuple (256, 8, 6, 8) into the pytest.mark.parametrize list in tests/unittest/_torch/thop/parallel/test_noaux_tc.py; this tuple yields experts_per_group=32 and topk_group=6 (product 192) which triggers the LargeMaxNumTopGroups=8 path in noAuxTcKernels.cu, so ensure it is placed among the existing cases in the parameter list used by the test function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/unittest/_torch/thop/parallel/test_noaux_tc.py`:
- Around line 8-19: Add a new parameterized test case to exercise the
MaxNumTopGroups=8 kernel path by inserting the tuple (256, 8, 6, 8) into the
pytest.mark.parametrize list in
tests/unittest/_torch/thop/parallel/test_noaux_tc.py; this tuple yields
experts_per_group=32 and topk_group=6 (product 192) which triggers the
LargeMaxNumTopGroups=8 path in noAuxTcKernels.cu, so ensure it is placed among
the existing cases in the parameter list used by the test function.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 6aa31ba0-bc47-4a08-8b35-dab5e3be5618
📒 Files selected for processing (5)
cpp/tensorrt_llm/kernels/moeTopKFuncs.cuhcpp/tensorrt_llm/kernels/noAuxTcKernels.cutensorrt_llm/_torch/modules/fused_moe/communication/deep_ep.pytensorrt_llm/_torch/modules/fused_moe/routing.pytests/unittest/_torch/thop/parallel/test_noaux_tc.py
|
PR_Github #45430 [ run ] triggered by Bot. Commit: |
|
PR_Github #45430 [ run ] completed with state
|
|
/bot run |
|
PR_Github #45587 [ run ] triggered by Bot. Commit: |
|
PR_Github #45587 [ run ] completed with state
|
Signed-off-by: Christina Zhang <83400082+ChristinaZ@users.noreply.github.com>
Signed-off-by: Yue Weng <25103990+yweng0828@users.noreply.github.com>
24dec37 to
db3381f
Compare
|
/bot run |
|
PR_Github #45642 [ run ] triggered by Bot. Commit: |
|
PR_Github #45642 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #45739 [ run ] triggered by Bot. Commit: |
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Tests
Description
Update the customized kernel and its application range of Deepseekv3Routing.
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.